
import 'package:flutter/material.dart';
import 'package:short_video/entity/profile/my_user_info_entity.dart';
import 'package:short_video/ui/pages/profile/fans_page.dart';
import 'package:short_video/ui/pages/profile/follow_page.dart';
import 'package:short_video/ui/pages/profile/setting_page.dart';
import 'package:short_video/ui/pages/publish/publish_page.dart';
import 'package:short_video/utils/navigator_util.dart';

import '../../network/base_entity.dart';
import '../../network/http_manager.dart';
import '../../utils/hud_util.dart';

class ProfileViewModel extends ChangeNotifier {
  List<String> tabs = ["作品","喜欢"];
  TabController? tabController;
  int currentIndex = 0;
  MyUserInfoEntity? entity;

  ProfileViewModel({required TickerProvider vsync}) {
    tabController = TabController(initialIndex: currentIndex, length: tabs.length, vsync: vsync);
    _requestData();
  }

  Future _requestData() async {
    Map<String, dynamic> params = {};
    HudUtil.show();
    IBaseEntity? result = await HttpManager.getInstance().request(url: "/api/app/user/info", params: params);
    HudUtil.dismiss();
    if (result?.isSuccess() == true) {
      MyUserInfoEntity tempEntity = MyUserInfoEntity.fromJson(result?.getData());
      entity = tempEntity;
      notifyListeners();

    } else {
      HudUtil.toast(result?.getMsg() ?? "");
    }
  }

  void setting(BuildContext context) {
    NavigatorUtil.push(context, const SettingPage());
  }

  void fans(BuildContext context) {
    NavigatorUtil.push(context, const FansPage());
  }

  void follow(BuildContext context) {
    NavigatorUtil.push(context, const FollowPage());
  }

  void publish(BuildContext context) {
    NavigatorUtil.push(context, const PublishPage());
  }
}